package test;

import com.itstyle.quartz.kettleUtil.FileReadUtil;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @author ycj
 * @version 1.0
 * @description
 * @date 2021/1/11 14:31
 */
public class text3 implements Runnable{

    List<File> filePathsList = new ArrayList<File>();
    int index = 0;

    public text3() {
        File f = new File("D:\\dianli\\工作材料\\k");
        getFileList(f);
    }

    private void getFileList(File f) {
        File[] filePaths = f.listFiles();
        for (File s : filePaths) {
            if (s.isDirectory()) {
                getFileList(s);
            } else {
                filePathsList.add(s);
            }
        }
    }

    @Override
    public void run() {
        File file = null;
        while (index < filePathsList.size()) {
            synchronized (this) {
                if (index >= filePathsList.size()) {
                    continue;
                }
                file = filePathsList.get(index);
                index++;
            }

            try {
                Thread.sleep(300);
            } catch (InterruptedException e2) {
                e2.printStackTrace();
            }
            HashMap<String, List<String>> read = FileReadUtil.read(file.getPath());
            System.out.println(read);

            System.out.println("当前使用的线程是："
                    + Thread.currentThread().getName() + ",正在读文件:"
                    + filePathsList.indexOf(file) + ",列表当前长度:"
                    + filePathsList.size()
                    + ",文件名"
                    + file.getPath());
        }
    }
}

